import java.util.Arrays;


    /**
     * @Author 12629
     * @Description：
     */
    public class Test {

        public static int find(int[] array,int val) {
            for (int i = 0; i < array.length; i++) {
                if(array[i] == val) {
                    return i;
                }
            }
            return -1;
        }

        public static void main(String[] args) {
            int[] array1 = {1,12,3,14};
            int ret = find(array1,14);
            System.out.println(ret);
        }

        public static void main22(String[] args) {
            int[] array1 = {1,2,3,4};
            int[] array2 = array1.clone();
            System.out.println(Arrays.toString(array1));
            System.out.println(Arrays.toString(array2));
            System.out.println("===========");
            array2[0] = 199;
            System.out.println(Arrays.toString(array1));//1 2 3 4
            System.out.println(Arrays.toString(array2));// 199 2 3 4
        }

        public static void main21(String[] args) {
            int[] array1 = {1,2,3,4};
            int[] array2 = {1,2,31,4};
            //System.out.println(array1 == array2);
            System.out.println(Arrays.equals(array1,array2));


            int[] array3 = new int[10];
            Arrays.fill(array3,1,3,-1);//[1,3)
            System.out.println(Arrays.toString(array3));


        }

        public static void main20(String[] args) {
            int[] array = {1,2,3,4,5};
            //可以当做扩容来用
            int[] ret = Arrays.copyOfRange(array,1,3);//[1,3)

            System.out.println(Arrays.toString(array));
            System.out.println(Arrays.toString(ret));

        }

        public static void main19(String[] args) {
            int[] array = {1,2,3,4};
            //可以当做扩容来用
            int[] ret = Arrays.copyOf(array,array.length/2);

            System.out.println(Arrays.toString(array));
            System.out.println(Arrays.toString(ret));
            System.out.println("===========");
            ret[0] = 199;
            System.out.println(Arrays.toString(array));//1 2 3 4
            System.out.println(Arrays.toString(ret));// 199 2 3 4
        }

        public static void main18(String[] args) {
            int[] array = {1,2,3,4};
            //可以当做扩容来用
            int[] copy = new int[array.length];

            //System.arraycopy(array,0,copy,0,array.length);
            System.arraycopy(array,1,copy,1,array.length-1);

            System.out.println(Arrays.toString(array));
            System.out.println(Arrays.toString(copy));
            System.out.println("===========");
            copy[0] = 199;
            System.out.println(Arrays.toString(array));//1 2 3 4
            System.out.println(Arrays.toString(copy));// 199 2 3 4
        }

        public static void main17(String[] args) {
            int[] array = {1,2,3,4};
            //可以当做扩容来用
            int[] ret = Arrays.copyOf(array,array.length*2);
            System.out.println(Arrays.toString(array));
            System.out.println(Arrays.toString(ret));
            System.out.println("===========");
            ret[0] = 199;
            System.out.println(Arrays.toString(array));//1 2 3 4
            System.out.println(Arrays.toString(ret));// 199 2 3 4
        }

        public static void main16(String[] args) {
            int[] array = {1,2,3,4};

            int[] array2 = new int[array.length];

            for (int i = 0; i < array.length; i++) {
                array2[i] = array[i];
            }

            System.out.println(Arrays.toString(array));
            System.out.println(Arrays.toString(array2));

            System.out.println("===========");

            array2[0] = 199;
            System.out.println(Arrays.toString(array));//1 2 3 4
            System.out.println(Arrays.toString(array2));// 199 2 3 4

        }

        public static void main15(String[] args) {
            int[] array = {1,2,3,4};
            System.out.println(Arrays.toString(array));
            int[] array2 = array;
            System.out.println(Arrays.toString(array2));
        }

        public static String myToString(int[] array) {
            if(array == null) {
                return "null";
            }
            String ret = "[";
            for (int i = 0; i < array.length; i++) {
                ret += array[i];
                if(i != array.length-1) {
                    ret += ", ";
                }
            }
            ret = ret + "]";
            return ret;
        }

        public static void main14(String[] args) {
            int[] array = {1,2,3,4};
            System.out.println(myToString(array));
            System.out.println(myToString(null));
        }

        public static int[] func10() {
            int[] tmpArr = {10,11,12};
            return tmpArr;
        }

        /**
         * 将数组array里面的每个元素都 扩大2倍
         * @param array
         * @return
         */
        public static int[] grow(int[] array) {
            for (int i = 0; i < array.length; i++) {
                array[i] = array[i]*2;
            }
            return array;
        }

        public static void grow2(int[] array) {
            for (int i = 0; i < array.length; i++) {
                array[i] = array[i]*2;
            }
        }

        public static void main12(String[] args) {
            int[] array = {1,2,3,4,6,7,8};
            grow2(array);
            System.out.println(Arrays.toString(array));
        }

        public static int[] grow3(int[] array) {
            //                         Java 里面可以是变量
            int[] tmpArray = new int[array.length];
            for (int i = 0; i < array.length; i++) {
                tmpArray[i] = array[i]*2;
            }
            return tmpArray;
        }

        public static void main13(String[] args) {
            int[] array = {1,2,3,4,6,7,8};
            int[] ret = grow3(array);
            System.out.println(Arrays.toString(array));
            System.out.println(Arrays.toString(ret));
        }


        public static void function(int b) {
            b = 20;
        }

        public static int function2(int b) {
            b = 20;
            return b;
        }

        public static void main8(String[] args) {
            int a = 10;
            function(a);
            System.out.println(a);
            int ret = function2(a);
            System.out.println(ret);
        }

        public static void func1(int[] array) {
            array = new int[]{15,16,17};
            //从这里下面 都改变了实参的值了
        }

        public static void main7(String[] args) {
            int[] array1 = {1,2,3,4};
            func1(array1);
            System.out.println(Arrays.toString(array1));
        }

        //形参
        public static void func2(int[] array) {
            array[0] = 999;
        }

        public static void main6(String[] args) {
            int[] array1 = {1,2,3,4};
            //func1(array1);
            func2(array1);//实参
            System.out.println(Arrays.toString(array1));

        }

        public static void main5(String[] args) {
            int[] array1 = {1,2,3,4};
            int[] array2 = {11,22,33,44};
            array1 = array2;
            array1[0] = 1888;
            System.out.println(Arrays.toString(array1));
            System.out.println(Arrays.toString(array2));
        }

        public static void main4(String[] args) {
            int[] array1 = {1,2,3,4};
            array1[0] = 99;

            int[] array2 = array1;
            array2[0] = 100;

            System.out.println(Arrays.toString(array1));//
            System.out.println(Arrays.toString(array2));//
        }

        public static void main3(String[] args) {
            int[] array4 = null;
            System.out.println(array4.length);
        }

        public static void main2(String[] args) {
            int[] array1 = {1,2,3,4};
            int[] array2 = new int[]{1,2,3,4};
            int[] array3 = new int[10];

            int[] array4 = null;
            System.out.println(array4);

            int a = 0;
            System.out.println(a);
        }



        public static void main1(String[] args) {
            int[] array = new int[100];
            for (int i = 0; i < array.length; i++) {
                array[i] = i+1;
            }
            printArray(array);
            //System.out.println(Arrays.toString(array));
        }

        public static void printArray(int[] array) {
            for (int i = 0; i < array.length; i++) {
                System.out.print(array[i]+" ");
            }
            System.out.println();
        }
    }


